package com.dyh.quickdemozwei.pipe0823;

public interface PipeNode {

    Object work(ValueContext valueContext);

    int index();

    default <T> T getLastInputValue(ValueContext valueContext,Class<T> clazz){
        return getInputValue(Math.min(index()-1,0),valueContext,clazz);
    }

    default <T> T getInputValue(int index,ValueContext valueContext,Class<T> clazz){
        Object raw = valueContext.getOutputs()[index];
        if (raw==null)
            return null;
        if (clazz.isAssignableFrom(raw.getClass()) )
            return clazz.cast(raw);
        return null;
    }
}
